package com.qf.dao;

import com.qf.entity.Member;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface MemberMapper {


    List<Member> findByName(String name);

    @Insert("insert into t_member(id,fileNumber,name,sex,idCard,phoneNumber,regTime,password,email,birthday,remark,ethmic,maritalntatus,job,education,origo)" +
            "values (#{id},#{fileNumber},#{name},#{sex},#{idCard},#{phoneNumber},#{regTime},#{password},#{email},#{birthday},#{remark},#{ethmic},#{maritalntatus},#{job},#{education},#{origo} )")
    int insert(Member member);

    @Update("update t_member set fileNumber=#{fileNumber},name=#{name},sex=#{sex},idCard=#{idCard},phoneNumber=#{phoneNumber},regTime=#{regTime},password=#{password}" +
            ",email=#{email},birthday=#{birthday},remark=#{remark},ethmic=#{ethmic},maritalntatus=#{maritalntatus},job=#{job},education=#{education},origo=#{origo} where" +
            " id=#{id}")
    int edit(Member member);

    @Delete("delete from t_member where id=#{id}")
    int delete(Integer id);

    @Select("select * from t_member where id=#{id}")
    Member findById(@Param("id") Integer id);




    @Select("select count(*) from t_member where regTime= CURDATE()")
    long todayAddMemberCount();

    @Select("select count(*) from t_member where regTime between SUBDATE(CURDATE(),DATE_FORMAT(CURDATE(),'%w')-1) and SUBDATE(CURDATE(),DATE_FORMAT(CURDATE(),'%w')-7)")
    long weekAddMemberCount();

    @Select("select count(*) from t_member where regTime between DATE_ADD(CURDATE(),INTERVAL -DAY(CURDATE())+1 DAY) and LAST_DAY(CURDATE())")
    long monthAddMemberCount();

    @Select("select count(*) from t_member")
    long memberCount();

    @Select("select count(*) from t_order where orderDate = CURDATE()")
    long todayOrderNumber();

    @Select("select count(*) from t_order where orderDate = CURDATE() and orderStatus = '已到诊'")
    long todayVisitsNumber();

    @Select("select count(*) from t_order where orderDate between SUBDATE(CURDATE(),DATE_FORMAT(CURDATE(),'%w')-1) and SUBDATE(CURDATE(),DATE_FORMAT(CURDATE(),'%w')-7)")
    long thisWeekOrderNumber();

    @Select("select count(*) from t_order where orderStatus = '已到诊' and orderDate between SUBDATE(CURDATE(),DATE_FORMAT(CURDATE(),'%w')-1) and SUBDATE(CURDATE(),DATE_FORMAT(CURDATE(),'%w')-7)")
    long thisWeekVisitsNumber();

    @Select("select count(*) from t_order where orderDate between DATE_ADD(CURDATE(),INTERVAL -DAY(CURDATE())+1 DAY) and LAST_DAY(CURDATE())")
    long thisMonthOrderNumber();

    @Select("select count(*) from t_order where orderStatus = '已到诊' and orderDate between DATE_ADD(CURDATE(),INTERVAL -DAY(CURDATE())+1 DAY) and LAST_DAY(CURDATE())")
    long thisMonthVisitsNumber();

    List<Map> findHostSetmeal();

}

